package com.liuwei.spring.cloud.junit.threads;

public class ThreadJunit {
    
    public static void main(String[] args) {
        joinTest();
    }

    private static void joinTest(){
        Thread child = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println(Thread.currentThread().getName()+"线程执行..."+i);
            }
        },"child");
        child.start();

        // 调用 child 的join方法，当前线程等待，等待child线程执行后再执行当前线程
        // 当前 main 现成处于 WAITING 状态，等待子线程完成
        try {
            child.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+"线程执行..."+i);
        }
    }
}
